package net.uhuijia.utils;

import java.util.Map;
import java.util.Random;

public class BaseStringUtils {
	/**
	 * 
	 * @param url
	 * @param params
	 * @return
	 */
	public static String bracketReplace(String str,Map<String,Object> params){
		for(String key:params.keySet())
			str = str.replace(new StringBuilder("{").append(key).append("}").toString(), params.get(key)==null?"":params.get(key).toString());
		return str;
	}
	
	public static String converSqlStrToHtml(String str){
		if(str!=null)
			return str.replace("\n", "<br>").replace(" ", "&nbsp;");
		else
			return null;
	}
	
	public static String converSqlStrToNHtml(String str){
		if(str!=null)
			return str.replace("\n", "\n").replace(" ", "&nbsp;");
		else
			return null;
	}
	
	public static String random(int length) { //length表示生成字符串的长度
	    String base = "abcdefghijklmnopqrstuvwxyz0123456789";   
	    Random random = new Random();   
	    StringBuffer sb = new StringBuffer();   
	    for (int i = 0; i < length; i++) {   
	        int number = random.nextInt(base.length());   
	        sb.append(base.charAt(number));   
	    }   
	    return sb.toString();   
	 }  
}
